package com.hilaver.dzmis.exhibition.service;

import java.util.List;

import com.hilaver.dzmis.exhibition.hibernate.Color;
import com.hilaver.dzmis.exhibition.hibernate.TechnicChartMaterial;
import com.hilaver.dzmis.exhibition.hibernate.Yarn;
import com.hilaver.dzmis.exhibition.utils.Constants;

public class YarnService extends AbstractBaseService {

	public String delete(int id) throws Exception {
		return super.delete(Yarn.class.getName(), id);
	}

	public String get(int id) throws Exception {
		return super.get(Yarn.class.getName(), id);
	}

	public String getAllPagination(int page, String sort, String order)
			throws Exception {
		return super.getAllPagination(Yarn.class.getName(), page, sort, order);
	}

	public String getAllPagination(int page, String sort, String order,
			String[] filters) throws Exception {
		return super.getAllPagination(Yarn.class.getName(), page, sort, order,
				filters);
	}

	public String getAll(String sort, String order) throws Exception {
		return super.getAll(Yarn.class.getName(), sort, order);
	}

	public String getAllFromTechnicChartId(Integer tcId)  throws Exception{
		String[] filters = new String[1];
		int offset = 0;
		filters[0] = "technicChart.id = " + tcId;
		List<TechnicChartMaterial> objList = this.dao.getAll(TechnicChartMaterial.class.getName(), "id", Constants.ORDER_ASC, filters);
		StringBuffer xmlSB = new StringBuffer();
		xmlSB.append(Constants.XML_DOC_DEFINE);
		xmlSB.append(Constants.XML_ROOT_TAG[0]);
		for (TechnicChartMaterial obj : objList) {
			xmlSB.append(Constants.XML_ITEM_TAG[0]);
			xmlSB.append(Constants.XML_INDEX_TAG[0]);
			xmlSB.append(++offset);
			xmlSB.append(Constants.XML_INDEX_TAG[1]);
			
			xmlSB.append("<id>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getId());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</id>");
			
			xmlSB.append("<unitPrice>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getUnitPrice());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</unitPrice>");
			
			xmlSB.append("<q1>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getQ1() == null?"":obj.getQ1());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</q1>");
			
			xmlSB.append("<c1>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getC1() == null?"":obj.getC1());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</c1>");
			
			xmlSB.append("<q2>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getQ2() == null?"":obj.getQ2());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</q2>");
			
			xmlSB.append("<c2>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getC2() == null?"":obj.getC2());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</c2>");
			
			xmlSB.append("<q3>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getQ3() == null?"":obj.getQ3());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</q3>");
			
			xmlSB.append("<c3>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getC3() == null?"":obj.getC3());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</c3>");
			
			xmlSB.append("<q4>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getQ4() == null?"":obj.getQ4());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</q4>");
			
			xmlSB.append("<c4>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getC4() == null?"":obj.getC4());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</c4>");
			
			xmlSB.append("<q5>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getQ5() == null?"":obj.getQ5());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</q5>");
			
			xmlSB.append("<c5>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getC5() == null?"":obj.getC5());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</c5>");
			
			xmlSB.append("<otherCo>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getOtherCo() == null?"":obj.getOtherCo());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</otherCo>");
			
			xmlSB.append("<technicChart>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getTechnicChart().getReference());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</technicChart>");
			
			xmlSB.append("<yarnName>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getYarn().getName());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</yarnName>");
			
			xmlSB.append("<yarnId>");
			xmlSB.append(Constants.XML_CDATA[0]);
			xmlSB.append(obj.getYarn().getId());
			xmlSB.append(Constants.XML_CDATA[1]);
			xmlSB.append("</yarnId>");
			
			
			xmlSB.append(Constants.XML_ITEM_TAG[1]);
		}
		
		xmlSB.append(Constants.XML_ITEM_TOTAL_TAG[0]);		
		xmlSB.append(Constants.XML_ITEM_TOTAL_TAG[1]);

		xmlSB.append(Constants.XML_ROOT_TAG[1]);
		return xmlSB.toString();
	}

	public Yarn getObj(int id) throws Exception {
		return (Yarn) super.getObj(Yarn.class.getName(), id);
	}
}
